<template>
	<view class="archives">
		<u-navbar :autoBack="true" title="分享好友"  :placeholder="true"></u-navbar>
		<view class="header-bg">
			<view class="h-me">
				<img src="@/static/img/invite-bg.png" class="code-bg" />
				<view class="me-1 flex-box">
					<view class="left">
						<img :src="userInfo.headimg" class="head"/>
					</view>
					<view class="right">
						<view class="hd">{{userInfo.nickname}}的二维码</view>
						<view class="desc">告诉小伙伴我在星火·女神邦~</view>
					</view>
				</view>
        <view class="bm-content flex-box">
          <image :src="info.ewm" class="wx-code" @tap="saveImg"></image>
        </view>
<!--				<view class="bm-content">
					&lt;!&ndash; <view class="">
						我的推广码：{{info.code}}
					</view> &ndash;&gt;
					<view class="canvas">
						<canvas canvas-id="qrcode"></canvas>
					</view>
				</view>-->
				
			</view>
			
		</view>
	</view>
</template>

<script>
	import uQRCode from '@/common/uqrcode.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				// 二维码标识串
				qrcodeText: '',
				infor:{},
				info:{},
				code:null,
			};
		},
		computed: {
			...mapState(['hasLogin','userInfo'])
		},
		onLoad(option) {
			if(option.code){
				uni.setStorageSync('code', option.code);
			}
			this.initData()
		},
		methods:{
			make() {

			/*	uQRCode.make({
					canvasId: 'qrcode',
					text: this.qrcodeText,
					size: 150,
					margin: 0,
					complete: () => {
						uni.hideLoading()
					}
				})*/
			},
			initData(){
       /* uni.showLoading({
          title: '二维码生成中',
          mask: true
        })*/
				this.$u.api.inviteCode()
				.then(res=>{
					this.info = res.msg
					this.qrcodeText = res.msg.ewm
					uni.setStorageSync('code', res.msg.code);
					// this.make()
          if (!res.status){
              uni.showToast({title:res.msg,icon:'none',success(){

                }},)
              setTimeout(function (){
                uni.navigateBack()
              },2000)
          }
				})
				.catch(err=>{
					console.log(err);
				})
			},
		}
	}
</script>

<style lang="scss">
	@import 'invite.scss';
	.canvas{
		width: 400rpx;
		height: 400rpx;
		margin:0 auto;
	}
</style>
